package servlet;
import java.util.ArrayList;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.User;
import db.DB;
public class MainServlet extends HttpServlet{
	 protected void doGet(HttpServletRequest req,HttpServletResponse res)
     throws ServletException,IOException{
		 req.setCharacterEncoding("gb2312");
		 res.setContentType("gb2312");
		 String username=req.getParameter("username");
		 String pwd=req.getParameter("pwd");
		 DB db=new DB();
		 HttpSession session=req.getSession();
		 User user=(User)session.getAttribute("user");
		 if(user==null){
			 user=db.checkUser(username,pwd);
		 }
		 session.setAttribute("user",user);
		 if(user!=null){
			 ArrayList al=db.findLyInfo();
			 session.setAttribute("al",al);
			 res.sendRedirect("main.jsp");
			 
		 }else{
			 res.sendRedirect("login.jsp");
		 }
	 }
	 protected void doPost(HttpServletRequest req,HttpServletResponse res)
     throws ServletException,IOException{
   	  doGet(req,res);
     }
}
